package com.ruoyi.traces.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.traces.domain.TraceLngLat;
import com.ruoyi.traces.service.DriverService;
import com.ruoyi.traces.service.TraceLngLatService;
import com.ruoyi.traces.utils.HBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/driver")
public class DriverController {

    @Autowired
    private DriverService driverService;

    @Autowired
    TraceLngLatService traceLngLatService;
    @GetMapping("/listTransport/{driverId}")
    public AjaxResult listTransport(@PathVariable("driverId") String driverId){
        return AjaxResult.success(driverService.listTransport(driverId));
    }


    @PostMapping("/saveAndUpdateTransportInfoToDb")
    public AjaxResult saveAndUpdateTransportInfoToDb(@RequestBody TraceLngLat traceLngLat) {
        traceLngLatService.saveGpsTable(traceLngLat);
        return AjaxResult.success(driverService.saveAndUpdateTransportInfoToDb(traceLngLat));
    }

    /**
     * hbase 保存经纬度
     *
     * @param traceLngLat
     * @return
     */
    @PostMapping("saveGpsTable")
    public AjaxResult saveGpsTable(@RequestBody TraceLngLat traceLngLat){
        traceLngLatService.saveGpsTable(traceLngLat);
        return AjaxResult.success("保存成功");
    }

    /**
     * 通过 hbase 查询经纬度
     *
     * @param cropsId
     * @return
     */
    @GetMapping("/getGpsTable/{cropsId}")
    public AjaxResult getGpsTable(@PathVariable("cropsId") String cropsId){
        List<TraceLngLat> gpsTable = traceLngLatService.getGpsTable(cropsId);
        System.out.println(gpsTable);
        return AjaxResult.success(gpsTable);
    }
}
